Jimmy and the flash memories - HackerRank Solutions - HackerRank Solutions

Breaking

Post Top Ad

Post Top Ad

Thursday, June 25, 2020

Jimmy and the flash memories - HackerRank Solutions

Jimmy is preparing for a coding challenge, and for unknown reasons, he wants to store all the solutions of the contestants in flash memories.

The contest is over, and there are n solutions, all the solutions have the same size which is x GB, and each flash memory could store at most a GB.

Notice that you can't split one file and store it multiple memory, each file has to be stored in a single memory.

Jimmy went to Joey's store to buy some flash memories, can you tell him what is the minimum number of flash memories he has to by to store all the solutions?

Input Format
The input contains 3 integers n, x, a

Constraints
1 ≤ n ≤ 105
1 ≤ x ≤ a ≤ 105

Output Format
Print the minimum number of flash memories Jimmy has to buy.

Sample Input 0
10 2 7

Sample Output 0
4

Explanation 0
In the first sample, there are 10 files each of them of size 2GB, and each flash memory could store at most 7GB so it could contain at most 3 files of size 2GB, so Jimmy needs 4 flash memories to store 10 files of size 2GB.

Sample Input 1
3 5 15

Sample Output 1
1


Jimmy and the flash memories - HackerRank  Solutions 

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
    int n,x,a,totalsize,currentsize=0,j=0,balance=0;
    scanf("%d",&n);
    scanf("%d",&x);
    scanf("%d",&a);
    totalsize=n*x;
        while(1){
            if(totalsize<=currentsize)
                break;
            balance=a;
                
            while(1){
                if(balance<x ||  totalsize<=currentsize)
                    break;
                balance=balance-x;
    
                currentsize+=x;
            }
            j++;
        }
    printf("%d",j);
    return 0;
}

No comments:

Post a Comment

Post Top Ad